package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.domain.Tag;
import cn.wolfcode.trip.base.mapper.CommentMapper;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.service.ICommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;


    @Override
    public PageInfo<Comment> query(CommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        return new PageInfo<>(commentMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(Comment entity) {
        if (entity.getId()==null){
            commentMapper.insert(entity);
        }else {
            commentMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public Comment getComment(Long id) {
        return commentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Tag> getTagById(Long id) {
        return commentMapper.selectTagsById(id);
    }
}
